﻿/*-----------------------------------------------
// File: EngineMsgReceive.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using ProtoBuf.Message;
using Battle.Engine;

namespace Battle.Communication
{
    public class EngineMsgReceive 
    {
        public EngineMsgReceive() { }

        public void PushMessageToEngine(BattlePacket bp)
        {
            switch (bp.opcode)
            {
                case (int)OpDefine.CSNewRound:
                    AskRoundBegin(bp);
                    break;
                case (int)OpDefine.CSRoundOver:
                    AskRoundOver(bp);
                    break;
                case (int)OpDefine.CSTransBegin:
                    AskTrans(bp);
                    break;
                case (int)OpDefine.CSTransOver:
                    AskTransEnd(bp);
                    break;
                case (int)OpDefine.CSSkillCast:
                    AskSkillCast(bp);
                    break;
                case (int)OpDefine.CSJumpUltimate:
                    AskJumpUltimate();
                    break;
            }
            // TODO
        }
        void AskRoundBegin(BattlePacket bp) {
            BattleManager.Instance.battleEngine.NextRound();
        }

        void AskRoundOver(BattlePacket bp) {
            BattleManager.Instance.battleEngine.FinishRound();
        }

        void AskTrans(BattlePacket bp) {
            BattleManager.Instance.battleEngine.Pause();
            var _bp = new BattlePacket();
            _bp.opcode = OpDefine.SCTransBegin;
            _bp.kBody = new SCTransBegin();
            Battle.BattleMsgCtrl.GetInstance().msgCtrl.EngineSend(_bp);
        }

        void AskTransEnd(BattlePacket bp) {
            CSTransOver msg = bp.kBody as CSTransOver;
            BattleManager.Instance.battleEngine.DoTrans(msg.actorUids, msg.actorFPIds);
            BattleManager.Instance.battleEngine.Continue();
        }

        void AskSkillCast(BattlePacket bp) {
            CSSkillCast msg = bp.kBody as CSSkillCast;
            BattleManager.Instance.battleEngine.DoSkill((CampType)msg.camp, msg.actorUid, msg.skillType);
        }

        void AskJumpUltimate() {
            BattleManager.Instance.battleEngine.SkipUltimate();
        }
    }
}
